#-*- coding: UTF-8 -*-

import os
import xlrd
import xlutils.copy
import mpath

def setOutCell(outSheet, col, row, value):
   
    outSheet.write(row, col, value)
 
def getExcel(ename,list):
	if not list:
		print("无导出数据！")
		return False
	#指定原始excel路径
	filepath = r'%s\excel.xls'%(mpath.get_desktop())
	xlsname = r'%s.xls'%(ename)
	xlsnameadd = r'%s\%s.xls'%(mpath.getexcelpath(),ename)
	#rb打开该excel，formatting_info=True表示打开excel时并保存原有的格式
	rb = xlrd.open_workbook(filepath,formatting_info=True)
	#创建一个可写入的副本
	wb = xlutils.copy.copy(rb)
	outSheet = wb.get_sheet(0)
	i = 2
	for listd in list:
		setOutCell(outSheet,0,i,'/'+listd['partofproject'])
		setOutCell(outSheet,1,i,listd['patchtype'])
		setOutCell(outSheet,2,i,'*.'+listd['patchtype'])
		setOutCell(outSheet,3,i,listd['deploywhere'])
		setOutCell(outSheet,4,i,listd['fullpath'])
		setOutCell(outSheet,5,i,listd['bb1'])
		setOutCell(outSheet,6,i,listd['bb2'])
		setOutCell(outSheet,7,i,listd['owner'])
		i += 1
	wb.save(xlsnameadd)
	print(xlsname,'导出完成')




